package sjtu.ist.warehouse4ws.service;

import java.util.ArrayList;
import java.util.List;

import sjtu.ist.warehouse4ws.dao.DepartmentDao;
import sjtu.ist.warehouse4ws.dao.cust.CustDepartmentDao;
import sjtu.ist.warehouse4ws.model.CustDepartment;
import sjtu.ist.warehouse4ws.model.Department;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;

public class DepartmentServiceImpl implements DepartmentService {
	private DepartmentDao departmentDao;
	private CustDepartmentDao custDepartmentDao;
	
	public void setCustDepartmentDao(CustDepartmentDao custDepartmentDao) {
		this.custDepartmentDao = custDepartmentDao;
	}
	
	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}
	
	@Override
	public List<Department> getDepartmentList() {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findDepartment();
	}
	@Override
	public List<Department> getCompanyList() {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findCompany();
	}
	@Override
	public List<Department> getCompanyListByGroupAndVersion(String groupId,String versionId) {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findCompanyByGroupAndVersion(groupId,versionId);
	}
	@Override
	public void save(List<Department> DeptList,int companyId) {
		if(companyId==0){
			departmentDao.save(DeptList);
		}else{
			ArrayList<CustDepartment> list=new ArrayList<CustDepartment>();
			for(Department d : DeptList){
				CustDepartment cd=new CustDepartment();
				PropertyHelper.copyProperties(d, cd);
				list.add(cd);
			}
			custDepartmentDao.save(list);
		}
	}
	@Override
	public List getDepartmentById(String id) {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findDepartmentById(id);
	}
	@Override
	public List getDepartmentByGroupId(int groupId) {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findDepartmentByGroupId(groupId);
	}
	@Override
	public List getDepartmentByFileId(String fileId) {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findDepartmentByFileId(fileId);
	}
	@Override
	public List getDepartmentByGroupAndVersion(String groupId,String versionId) {
		// TODO Auto-generated method stub
		return (List<Department>)departmentDao.findDepartmentByGroupAndVersion(groupId,versionId);
	}

}
